package com.hnd.springframework.factory.support;

import com.hnd.springframework.BeansException;
import com.hnd.springframework.factory.BeanFactory;
import com.hnd.springframework.factory.config.BeanDefinition;

public abstract class AbstractBeanFactory extends DefaultSinletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String beanName) {
        return getBean(beanName, null);
    }

    @Override
    public Object getBean(String beanName, Object... args) {
        Object bean = getSingleton(beanName);
        if (bean != null) {
            return bean;
        }
        BeanDefinition beanDefinition = getBeanDefinition(beanName);

        bean = createBean(beanName, beanDefinition, args);


        return bean;
    }


    abstract BeanDefinition getBeanDefinition(String beanName) throws BeansException;

    abstract Object createBean(String beanName, BeanDefinition beanDefinition, Object... args) throws BeansException;
}
